package thired.class10_graph;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class Class01_BFS {
    public static void Bfs(Node start){
        if(start == null){
            return;
        }
        Queue<Node> help = new LinkedList<>();
        HashSet<Node> visited = new HashSet<>();
        help.add(start);
        visited.add(start);
        while (!help.isEmpty()){
            Node cur = help.poll();
            System.out.println(cur.value);
            for(Node next : cur.nexts){
                if(!visited.contains(next)){
                    help.add(next);
                    visited.add(next);
                }
            }
        }
    }

}
